import random
from datetime import datetime

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.103.43',
    'username': 'admin',
    'password': '@Abcd1234',
    'database': 'saas'
}
client = clickhouse_connect.get_client(**connect_info)
column_list = ['log_id', 'log_time', 'apply_name', 'apply_message', 'trigger_mode', 'authorization_condition',
               'treasury_apply_id', 'license_model', 'license_result', 'belong_resource', 'begin_time', 'end_time',
               'co_op_name', 'apply_time', 'approve_time', 'scene_id', 'collect_time', 'co_op_org_code',
               'resource_type', 'resource_ip', 'control_type', 'cooperate_type']
table_name = 'std_gold_apply_approve_log_local'
insert_data = []
for i in range(100000):
    log_id = str(random.randint(10 ** 17, 10 ** 19))
    str_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    log_time = datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
    apply_name = 'marco'
    apply_message = 'test for Mr.HE'
    trigger_mode = '00'
    authorization_condition = '01'
    treasury_apply_id = str(random.randint(10 ** 7, 10 ** 8))
    license_model = '00'
    license_result = '0'
    belong_resource = 'SHNGGRWZH'
    begin_time = datetime.strptime('2025-03-01 13:00:00', '%Y-%m-%d %H:%M:%S')
    end_time = datetime.strptime('2025-03-01 15:00:00', '%Y-%m-%d %H:%M:%S')
    co_op_name = 'Curry'
    apply_time = datetime.strptime('2025-03-01 12:13:24', '%Y-%m-%d %H:%M:%S')
    approve_time = datetime.strptime('2025-03-01 12:19:54', '%Y-%m-%d %H:%M:%S')
    scene_id = '15201'
    collect_time = log_time
    co_op_org_code = '197'
    resource_type = '应用系统'
    resource_ip = '192.168.2.109'
    control_type = 'CT_CONTENT_TRIGER'
    cooperate_type = 'test'
    insert_data.append(
        [log_id, log_time, apply_name, apply_message, trigger_mode, authorization_condition, treasury_apply_id,
         license_model, license_result, belong_resource, begin_time, end_time, co_op_name, apply_time, approve_time,
         scene_id, collect_time, co_op_org_code, resource_type, resource_ip, control_type, cooperate_type])
client.insert(table_name, data=insert_data, column_names=column_list)
client.close()
